<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8"/>
    <title>用户登陆</title>
    <link rel="stylesheet" th:href="@{/css/bootstrap.min.css}" href="../../css/bootstrap.min.css"/>
    <link rel="stylesheet" th:href="@{/css/mystyle.css}" href="../../static/css/mystyle.css" />
</head>
<body>
<div class="container background">
    <div style="height: 50px"></div>
    <div th:replace="fragments :: navbar"></div>
    <div class="container">
        <div class="pull-right">
            <!--<a href="form.html" th:href="@{/(form)}">Create Message</a>-->
        </div>
        <form class="form-auto">
            <div class="form-group">
                <label for="userName">用户名</label>
                <input name="userName" type="text" id="userName" class="form-control" placeholder="用户名"/>
            </div>
            <div class="form-group">
                <label for="password">密码</label>
                <input name="password" type="password" class="form-control" id="password" placeholder="密码"/>
            </div>
            <button id="login" type="button" class="btn btn-primary">登录</button>
            <button id="toList" type="button" class="btn btn-default" style="margin-left: 15px">返回列表</button>
        </form>
        <div id="show"></div>
    </div>
</div>

<script type="text/javascript" th:src="@{/daiwei/scripts/rsa/Barrett.js}"
        src="../../static/daiwei/scripts/rsa/Barrett.js"></script>
<script type="text/javascript" th:src="@{/daiwei/scripts/rsa/Base64.js}"
        src="../../static/daiwei/scripts/rsa/Base64.js"></script>
<script type="text/javascript" th:src="@{/daiwei/scripts/rsa/BigInt.js}"
        src="../../static/daiwei/scripts/rsa/BigInt.js"></script>
<script type="text/javascript" th:src="@{/daiwei/scripts/rsa/RSA.js}"
        src="../../static/daiwei/scripts/rsa/RSA.js"></script>
<script type="text/javascript" th:src="@{/js/jquery-1.7.2.js}"
        src="../../static/js/jquery-1.7.2.js"></script>
<script type="text/javascript" th:src="@{/plugin/layer/layer.js}"
        src="../../static/plugin/layer/layer.js"></script>
<script type="text/javascript">
    $("#login").click(function () {
        var userId = $("input[name=userName]").val();
        var pwd = $("input[name=password]").val();
        $.ajax({
            url:"/monitor/RSAKey",
            type:"post",
            data:{userName:userId},
            dataType:"json",
            success:function (result) {
                setMaxDigits(262);
                var key=new RSAKeyPair(result.e,"",result.m,1024);
                var useridtext=base64_encode(encryptedString(key,userId,RSAAPP.PKCS1Padding,RSAAPP.RawEncoding));
                var pwdtext=base64_encode(encryptedString(key,pwd,RSAAPP.PKCS1Padding,RSAAPP.RawEncoding));
                loginPost(useridtext,pwdtext);
            },
            error:function (result) {

            }
        })
    })
    function loginPost(username,password) {
        var realName = $("input[name=userName]").val();
        $.ajax({
            url:"/monitor/loginPost",
            type:"post",
            data:{userName:username,password:password,realName:realName},
            success:function (result) {
                if(result == "ok"){
                    location.href = "/monitor/list";
                }else{
                    layer.alert("账号或者密码错误");
                }
//                $("#show").html(result);
            },
            error:function (result) {

            }
        })

    }
    $("#toList").click(function () {
        location = "/monitor/list";
    });
</script>

</body>
</html>